from flask import Flask,request
import json
import uuid
from main_local import generate_clip

app = Flask(__name__)

# 设置工作目录和项目相关的路径
WORKING_DIR = 'output'
SageMaker_ComfyUI = WORKING_DIR
workflowfile = './workflows/wan2.2_T2V.json'
COMFYUI_ENDPOINT = '121.14.34.215:16188'


server_address = COMFYUI_ENDPOINT
client_id = str(uuid.uuid4())  # 生成一个唯一的客户端ID
seed = 15465856
idx = 1
baseprompt = "a beautiful woman site front desktop "
# generate_clip(prompt, seed, workflowfile, idx)

@app.route("/v1/createImage",methods=["POST"])
def createImage():
    ret = {"code":200,"message":"SUCCESS","imageUrl":""}
    try:
        data = json.loads(request.data)
    except Exception as e:
        print(e)
        ret["code"] = 300
        ret["message"] = str(e)
        return json.dumps(ret)
    
    prompt = data["prompt"].strip()
    if prompt=="":
        prompt = baseprompt
        ret["message"] = "!!prompt is None,use default prompt!!"

    url = generate_clip(prompt, seed, workflowfile, idx,server_address,client_id)
    ret["imageUrl"] = url
    return json.dumps(ret)


if __name__ == "__main__":
    app.run("0.0.0.0",port=9001)

